package com.wp.module.wpUser.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wp.module.wpUser.domain.WpUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.wp.common.annotation.Log;
import com.wp.common.core.controller.BaseController;
import com.wp.common.core.domain.AjaxResult;
import com.wp.common.enums.BusinessType;
import com.wp.module.wpUser.service.IWpUserService;
import com.wp.common.utils.poi.ExcelUtil;
import com.wp.common.core.page.TableDataInfo;

/**
 * 用户信息Controller
 * 
 * @author wp
 * @date 2025-08-23
 */
@RestController
@RequestMapping("/module/wpUser")
public class WpUserController extends BaseController
{
    @Autowired
    private IWpUserService wpUserService;

    /**
     * 查询用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('module:wpUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(WpUser wpUser)
    {
        startPage();
        List<WpUser> list = wpUserService.selectWpUserList(wpUser);
        return getDataTable(list);
    }

    /**
     * 导出用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('module:wpUser:export')")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WpUser wpUser)
    {
        List<WpUser> list = wpUserService.selectWpUserList(wpUser);
        ExcelUtil<WpUser> util = new ExcelUtil<WpUser>(WpUser.class);
        util.exportExcel(response, list, "用户信息数据");
    }

    /**
     * 获取用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:wpUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(wpUserService.selectWpUserById(id));
    }

    /**
     * 新增用户信息
     */
    @PreAuthorize("@ss.hasPermi('module:wpUser:add')")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WpUser wpUser)
    {
        return toAjax(wpUserService.insertWpUser(wpUser));
    }

    /**
     * 修改用户信息
     */
    @PreAuthorize("@ss.hasPermi('module:wpUser:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WpUser wpUser)
    {
        return toAjax(wpUserService.updateWpUser(wpUser));
    }

    /**
     * 删除用户信息
     */
    @PreAuthorize("@ss.hasPermi('module:wpUser:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(wpUserService.deleteWpUserByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('module:wpUser:resetPwd')")
    @Log(title = "用户信息 -> 重置密码", businessType = BusinessType.UPDATE)
    @PutMapping("/resetWpUserPwd")
    public AjaxResult resetWpUserPwd(@RequestParam String id, @RequestParam String account){
        return toAjax(wpUserService.resetWpUserPwd(id, account));
    }
}
